﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Class_KetNoi;

namespace GiaoDien
{
    public partial class uc_KhenThuong : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_KhenThuong()
        {
            InitializeComponent();
        }
        KetNoi_KhenThuong kn=new KetNoi_KhenThuong();
        public void LoadDuLieu()
        {
            string sql="select * from tbl_KhenThuong";
            gridControl1.DataSource=kn.taobang(sql);
        }
        public void Nut()
        {
            btnThem.Enabled = false;
            btnSua.Enabled = false;
            btnXoa.Enabled = false;

            btnLuu.Enabled = true;
            btnHuy.Enabled = true;
        }
        private void uc_KhenThuong_Load(object sender, EventArgs e)
        {
            kn.connect();
            lbMaKhenThuong.Hide();
            txtMaKhenThuong.Hide();
            LoadDuLieu();

        }
        int flag;
        private void btnThem_Click(object sender, EventArgs e)
        {
            flag = 0;
            Nut();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Nut();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            kn.xoa_KhenThuong(txtMaKhenThuong.Text);
            LoadDuLieu();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if(flag==0)
            {
                kn.them_KhenThuong(txtTenKhenThuong.Text,date_NgayQuyetDinh.Text ,txtMaNhanVien.Text ,txtNoiDung.Text ,txtHinhThuc.Text);
            }
            if(flag==1)
            {
                kn.sua_KhenThuong(txtMaKhenThuong.Text ,txtTenKhenThuong.Text,date_NgayQuyetDinh.Text ,txtMaNhanVien.Text ,txtNoiDung.Text ,txtHinhThuc.Text);
            }
            LoadDuLieu();
  
            btnThem.Enabled =true;
            btnSua.Enabled = true;
            btnXoa.Enabled = true;

            btnLuu.Enabled = false;
            btnHuy.Enabled = false;
        
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            txtMaKhenThuong.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaLoaiKT").ToString();
            txtTenKhenThuong.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"TenLoaiKT").ToString();
            date_NgayQuyetDinh.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NgayQD").ToString();
            txtMaNhanVien.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaNV").ToString();
            txtNoiDung.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NoiDung").ToString();
            txtHinhThuc.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"HinhThuc").ToString();
        }
    }
}
